package cz.idsv.web.mvc.model.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * Pserson Entity.
 * 
 * @author Jan Borzensky
 */
@Entity(name = "Person")
@Table(name = "PERSON")
public class PersonEntity implements Serializable {

	private static final long serialVersionUID = -8712872385957386182L;

	private Integer id = null;
	private String firstName = null;
	private String lastName = null;
	private String age = null;
	private String email = null;
	private String mobile = null;
	private Set<AddressEntity> address = null;
	private Set<ProductEntity> product = null;
	private RegistrationEntity registration = null;

	/**
	 * Sets id (primary key).
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	/**
	 * Gets type.
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * 
	 * Sets id (primary key).
	 */
	@Column(name = "FIRST_NAME")
	public String getFirstName() {
		return firstName;
	}

	/**
	 * Gets type.
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * Sets id (primary key).
	 */
	@Column(name = "LAST_NAME")
	public String getLastName() {
		return lastName;
	}

	/**
	 * Gets type.
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * Sets id (primary key).
	 */
	@Column(name = "AGE")
	public String getAge() {
		return age;
	}

	/**
	 * Gets type.
	 */
	public void setAge(String age) {
		this.age = age;
	}

	/**
	 * Sets id (primary key).
	 */
	@Column(name = "EMAIL")
	public String getEmail() {
		return email;
	}

	/**
	 * Gets type.
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * Sets id (primary key).
	 */
	@Column(name = "MOBILE")
	public String getMobile() {
		return mobile;
	}

	/**
	 * Gets type.
	 */
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "REGISTRATION_ID")
	public RegistrationEntity getRegistration() {
    return this.registration;
	}
	public void setRegistration(RegistrationEntity registration) {
		this.registration = registration;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "PRODUCT_ID")
	public Set<ProductEntity> getProduct() {
		return product;
	}

	public void setProduct(Set<ProductEntity> product) {
		this.product = product;
	}

	@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@JoinColumn(name = "PERSON_ID")
	public Set<AddressEntity> getAddress() {
		return address;
	}

	public void setAddress(Set<AddressEntity> address) {
		this.address = address;
	}

	/**
	 * Returns a string representation of the object.
	 */
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		sb.append("  id=" + id);
		sb.append("  name=" + firstName);
		sb.append("  description=" + lastName);
		sb.append("  age=" + age);
		sb.append("  email=" + email);
		sb.append("  mobile=" + mobile);

		return sb.toString();
	}

	/**
	 * Returns a hash code value for the object.
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result + ((id == null) ? 0 : id.hashCode());

		result = prime * result
				+ ((firstName == null) ? 0 : firstName.hashCode());

		result = prime * result
				+ ((lastName == null) ? 0 : lastName.hashCode());

		result = prime * result + ((age == null) ? 0 : age.hashCode());

		result = prime * result + ((email == null) ? 0 : email.hashCode());

		result = prime * result + ((mobile == null) ? 0 : mobile.hashCode());

		return result;
	}

	/**
	 * Indicates whether some other object is equal to this one.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final PersonEntity other = (PersonEntity) obj;

		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}

		if (firstName == null) {
			if (other.firstName != null)
				return false;
		} else if (!firstName.equals(other.firstName))
			return false;

		if (lastName == null) {
			if (other.lastName != null)
				return false;
		} else if (!lastName.equals(other.lastName))
			return false;

		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (mobile == null) {
			if (other.mobile != null)
				return false;
		} else if (!mobile.equals(other.mobile))
			return false;

		return true;
	}

}
